<?php

require_once '../utils/response.php';
require_once  '../utils/db.php';

header('content-type:text/html;charset:utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET,POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$id = json_decode(file_get_contents("php://input"))->id;

// if (!is_numeric($id)) {
//     return Response::show(401, '数据不合法');
// }

// echo $id;
// exit;

try {
    $connect = Db::getInstance()->connect();
} catch (Exception $e) {
    return Response::show(403, '数据库连接失败', $e->getMessage());
}

//$sql = "SELECT news_maker FROM news WHERE news_id={$id}";
$sql = "DELETE FROM msg WHERE zwh_id ={$id}";

$res = $connect->query($sql);

$data = array(
    'IsDelete' => false
);

if ($res) {
    if ($connect->affected_rows == 1) {
        $data['IsDelete'] = true;
        return Response::show(200, '删除成功', $data);
    } else {
        return Response::show(404, '找不到留言数据', $data);
    }
} else {
    //    echo 'sql语句执行不成功';
    return Response::show(402, 'sql语句执行不成功', $data);
}
